﻿using AutoMapper.Configuration.Conventions;
using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.InterfaceService;
using MDT.LifeSewagePlatform.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.ServiceInstance.Controllers
{
    [Route("api/region")]
    [ApiController]
    [Authorize]
    public class RegionController : BaseController
    {
        #region prop and ctor
        [Autowired]
        private  IRegionService regionService  { get; set; }

        [Autowired]
        protected IDetailService detailRepository { get; set; }
        public RegionController()
        {
        }
        #endregion

        #region method service
        /// <summary>
        /// 完整地区信息
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet()]
        public async Task<BaseMessage> GetRegions([FromQuery] RegionParameter Params)
        {
            return await regionService.RegionsAsync(Params);
        }
        /// <summary>
        /// 下拉列表
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("place")]
        public async Task<BaseMessage> GetPlaces([FromQuery] RegionParameter Params)
        {
            return await regionService.RegionsKeyAsync(Params);
        }

        [HttpPost()]
        public async Task<BaseMessage> AddRegion([FromForm] RegionCreateOrUpdateDto RegionDto)
        {
            #region params verify 
            int UserId =GetUserID();
            #endregion
            return await regionService.AddAsync(RegionDto, UserId);
        }
        /// <summary>
        /// 更新地区
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="RegionDto"></param>
        /// <returns></returns>
        [HttpPut("{Id}")]
        public async Task<BaseMessage> UpdateRegion(int Id,[FromForm] RegionCreateOrUpdateDto RegionDto)
        {
            #region params verify 
            int UserId = GetUserID();
            #endregion
            return await regionService.UpdateAsync(Id,RegionDto,UserId);
          
        }
        /// <summary>
        /// 删除地区
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("{Id}")]
        public async Task<BaseMessage> Delete(int Id)
        {
            return await regionService.DeleteAsync(Id);
        }
        #endregion
    }
}
